<template>
  <el-card shadow="hover">
    <div slot="header">
      <span>商品图片</span>
    </div>
    <div class="imgs">
      <div class="item" v-for="(item, index) in list" :key="index">
        <span @click="handleDel(index)">删除</span>
        <el-image
          style="width: 100px; height: 100px"
          :src="item"
          :preview-src-list="[item]"
        >
        </el-image>
      </div>
      <Upload @upload="upload" :accept="'image/*'"></Upload>
    </div>


    <Cropped ref="Cropped" @success="success"></Cropped>
  </el-card>
</template>

<script>
import Upload from "@/components/uplaod/upload.vue";
import { uploadImg } from "@/utils";
import Cropped from "@/components/dialog/Cropped.vue";
export default {
  components: {
    Upload,
    Cropped
  },
  data() {
    return {
      list: [],
    };
  },
  methods: {
    set(data){
      this.list = data
    },
    upload(e) {
      this.$refs.Cropped.open(e)
    },
    success(e){
      uploadImg(e, null, {}, "light", (res) => {
          this.list.push(res);
          console.log(this.list);
        });
    },
    handleDel(index) {
      this.list.splice(index, 1);
    },
  },
};
</script>

<style lang="scss" scoped>
.imgs {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  margin-top: 5px;
  min-height: 368px;
  .item {
    border: 1px solid #cdcdcd;
    width: 100px;
    height: 100px;
    overflow: hidden;
    margin-right: 10px;
    position: relative;
    margin-bottom: 8px;
    border-radius: 5px;
    span {
      position: absolute;
      background-color: red;
      color: #fff;
      right: 5px;
      top: 5px;
      cursor: pointer;
      font-size: 12px;
      border-radius: 4px;
      padding: 2px 5px;
      z-index: 10;
    }
  }
}
</style>
